import setting from "./model/setting.js";
import lodash from "lodash";
import {_path, configPath, defaultPath, resourcePath} from "./model/path.js";
import path from 'path'

// 支持锅巴
export function supportGuoba() {

    let allGroup = [];
    Bot.gl.forEach((v, k) => {
        allGroup.push({label: `${v.group_name}(${k})`, value: k});
    });

    return {
        pluginInfo: {
            name       : 'fisticuffs-plugin',
            title      : '互殴插件 (fisticuffs-plugin)',
            author     : '@JK_An0nymou5',
            authorLink : 'https://gitee.com/JK_An0nymou5',
            link       : 'https://gitee.com/JK_An0nymou5/fisticuffs-plugin',
            isV3       : true,
            isV2       : false,
            description: '金毛脆脆鲨的打架骂人强化版，还提供master管理等功能',
            icon       : 'iconoir:3d-three-pts-box',
            iconColor  : '#45d0cc',
            iconPath   : path.join(resourcePath, 'images/readme/fisticuffs.jpg'),
        },
        // 配置项信息
        configInfo: {
            // 配置项 schemas
            schemas: [
                {
                    field         : 'application.absoluteMaster',
                    label         : '绝对权限QQ',
                    component     : 'Input',
                    required      : true,
                    componentProps: {
                        placeholder: '请输入绝对权限QQ',
                    },
                },
                {
                    field         : 'application.botName',
                    label         : '机器人名字',
                    component     : 'Input',
                    required      : true,
                    componentProps: {
                        placeholder: '请输入机器人名字',
                    },
                },
                {
                    field    : 'application.hitMaster',
                    label    : '是否打主人',
                    component: 'Switch'
                },
                {
                    field         : 'application.enableGroup',
                    label         : '启用互殴机器的群',
                    component     : 'Select',
                    componentProps: {
                        allowAdd: true,
                        allowDel: true,
                        mode    : 'multiple',
                        options : allGroup,
                    },
                },
                {
                    field    : 'application.onlyMe',
                    label    : '打人仅我可用',
                    component: 'Switch'
                },
                {
                    field         : 'application.crazyGroup',
                    label         : '疯狂模式的群',
                    component     : 'Select',
                    componentProps: {
                        allowAdd: true,
                        allowDel: true,
                        mode    : 'multiple',
                        options : allGroup,
                    },
                },
                {
                    field         : 'application.maxHitTimes',
                    label         : '最大打拳次数',
                    component     : 'Input',
                    required      : true,
                    componentProps: {
                        placeholder: '请输入最大打拳次数',
                    },
                },
                {
                    field         : 'application.abuseType',
                    label         : '骂人模式',
                    component     : 'Select',
                    required      : true,
                    componentProps: {
                        options    : [
                            {label: '可爱模式', value: 1},
                            {label: '正常模式', value: 2},
                            {label: '暴躁模式', value: 3},
                        ],
                        placeholder: '请选择骂人模式',
                    },
                },
                {
                    field    : 'application.arsehole',
                    label    : '跟屁虫',
                    component: 'Switch'
                },
            ],
            getConfigData() {
                return setting.merge()
            },
            // 设置配置的方法（前端点确定后调用的方法）
            setConfigData(data, {Result}) {
                let config = {}
                for (let [keyPath, value] of Object.entries(data)) {
                    lodash.set(config, keyPath, value)
                }
                config = lodash.merge({}, setting.merge, config)
                setting.analysis(config)
                return Result.ok({}, '保存成功~')
            }
        }
    }
}
